package com.yunxin.customui.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;

/**
 * 应用程序上下文
 *
 * @author lee
 * @date 2021/10/01
 */
@Configuration
public class ApplicationContextUtil implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    /**
     * 设置应用程序上下文
     *
     * @param applicationContext 应用程序上下文
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        ApplicationContextUtil.applicationContext = applicationContext;
    }

    /**
     * 得到对象
     *
     * @param beanName 对象名
     */
    public static Object getObject(String beanName) {
        Object object = null;
        object = applicationContext.getBean(beanName);
        return object;
    }

    /**
     * 获取spring上下文
     */
    public static ApplicationContext getSpringContext() {
        return applicationContext;
    }


}
